
Partial Class WebForm_SearchControl_SearchInternalUserControl
    Inherits My.MyUserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.Visible = False
    End Sub

    Protected Sub gv_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gv.PageIndexChanging
        Me.gv.PageIndex = e.NewPageIndex
        Me.Show()
    End Sub

    Protected Sub gv_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gv.RowCommand
        If e.CommandName = "Select" Then
            'Dim row As GridViewRow = TryCast(TryCast(e.CommandSource, Control).NamingContainer, GridViewRow)
            'Dim key As DataKey = Me.gv.DataKeys(row.RowIndex)

            Dim rowIndex As Integer = e.CommandArgument

            Me.gv.SelectedIndex = rowIndex

            'Me.SelectedUseName = TryCast(Me.gv.Rows(rowIndex).FindControl("lblPlanName"), Label).Text
            'Me.UOrganizationID = TryCast(Me.gv.Rows(rowIndex).FindControl("lblUOrganizationID"), Label).Text
            RaiseEvent SelectedIndexChanged(Me, New EventArgs)
        End If
    End Sub

    Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnQuery.Click
        Me.BindGV()
    End Sub
End Class

Partial Class WebForm_SearchControl_SearchInternalUserControl
    Public Sub Show()
        Me.InitData()
        Me.BindGV()
    End Sub

    Protected Sub InitData()
        Me.ddlOrganizationID.DataSource = Me.ObjectDataSource_UOrganizationData
        Me.ddlOrganizationID.DataBind()
        Me.ddlOrganizationID.SelectedValue = clsAuth.GetUser().UOrganizationID

    End Sub

    Private Sub BindGV()
        Dim dat As New clsData
        'Dim sql As New MyOrganizationDataFilter
        Dim sql As New MyStringBuilder

        sql.Length = 0
        sql.AppendFormat("select iu.* ")
        sql.AppendFormat(" from InternalUser iu ")
        sql.AppendFormat(" inner join OrganizationView o on iu.UOrganizationID = o.UOrganizationID ")
        sql.AppendFormat("where 1=1 ")
        sql.AppendFormat(Me.GetWhereSQL())

        Me.gv.DataSource = dat.GetData(sql)
        Me.gv.DataBind()

        Me.mpSearch.Show()
        Me.Visible = True
    End Sub

    Private Function GetWhereSQL() As String
        Dim sql As New MyStringBuilder

        If Me.ddlOrganizationID.SelectedValue <> "" Then
            sql.AppendFormat("and iu.UOrganizationID = '{0}' ", Me.ddlOrganizationID.SelectedValue)
        End If

        If Me.txtUserName.Text <> "" Then
            sql.AppendFormat("and iu.UserName like '%{0}%' ", Me.txtUserName.Text)
        End If

        Return sql.ToString()
    End Function

    Public ReadOnly Property SelectedUserID() As String
        Get
            Return Me.gv.SelectedDataKey("UserID")
        End Get
    End Property

    Public ReadOnly Property UserName() As String
        Get
            Return TryCast(Me.gv.SelectedRow.FindControl("lblUserName"), Label).Text
        End Get
    End Property

    Public ReadOnly Property PhoneNumber() As String
        Get
            Return TryCast(Me.gv.SelectedRow.FindControl("lblPhoneNumber"), Label).Text
        End Get
    End Property

    Public ReadOnly Property FaxPhoneNumber() As String
        Get
            Return TryCast(Me.gv.SelectedRow.FindControl("lblFaxPhoneNumber"), Label).Text
        End Get
    End Property

    Public ReadOnly Property Email() As String
        Get
            Return TryCast(Me.gv.SelectedRow.FindControl("lblEmail"), Label).Text
        End Get
    End Property

    Public ReadOnly Property UOrganizationID() As String
        Get
            Return TryCast(Me.gv.SelectedRow.FindControl("UOrganizationID"), HiddenField).Value
        End Get
    End Property

    Public ReadOnly Property OrganizationName() As String
        Get
            Return TryCast(Me.gv.SelectedRow.FindControl("lblOrganizationName"), Label).Text
        End Get
    End Property

    Public Event SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

End Class